package com.example.riskmanage.service.impl;

import com.alibaba.fastjson.JSON;
import com.example.riskmanage.bean.Riskyujing;
import com.example.riskmanage.dao.RiskyujingDao;
import com.example.riskmanage.service.RiskyujingManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class RiskyujingManagerImpl implements RiskyujingManager {

    @Autowired
    RiskyujingDao riskyujingDao;

    @Override
    public String getRiskyujingService(Integer uid) {
        HashMap<String,Object> map = new HashMap<>();

        //1.调用dao层接口获取数据
        List<Riskyujing> riskyujingList = riskyujingDao.findAllByUid(uid);
        //2.将处理的数据封装到map
        map.put("riskyujingList",riskyujingList);
        map.put("flag",true);


        String respJSON = JSON.toJSONString(map);
        return respJSON;
    }


    @Override
    public String addRiskyujingService(Riskyujing riskyujing) {
        riskyujingDao.save(riskyujing);
        return "ok";
    }

    @Override
    public String deleteRiskyujingService(Integer id) {
        riskyujingDao.deleteById(id);
        return "ok";
    }
}
